<?php

namespace app\index\controller;
use app\common\business\http\wechat\Wechat as wechatHttp;
/**
 * 会员控制器
 */
class Querylogin{

    /**
     * 快捷登录
     * 测试地址：/wap/querylogin/login/type/qq
     */
    public function login() { 
        $referer = isset($_REQUEST["http_referer"]) ? $_REQUEST["http_referer"] : '';  
       
        if (empty($referer)) {
            $referer = '/index/down/index';
        } else {
            $refererHttp = $referer;
            if (strpos($refererHttp, 'http') !== false) {
                $referer = $refererHttp;
            }  
        }
        setcookie('quickloginbackurl', $referer, time() + 7200, '/', '.qiu7.net'); 
        $querylogin = new wechatHttp();
        $backurl = 'https://xf2.qiu7.net/index/querylogin/loginback/type/weixin';
        echo $backurl;exit;
        // $backurl = 'http://m.qiu.vip/index/querylogin/loginback/type/weixin';
        $querylogin->getcode($backurl);
        exit;
    }

    /**
     * 快捷登录回调地址
     * 测试地址：/wap/querylogin/loginback/type/qq
     */
    public function loginback() {
        $params = input();
        //第三方回调 过来的code
        if (!isset($_REQUEST['code']) || empty($_REQUEST['code'])) {
            exception('参数错误', 100004);
        }
        $params['code'] = $_REQUEST['code'];
        $querylogin = new wechatHttp();
        $backurl = 'https://xf2.qiu7.net/index/querylogin/loginback/';
        $data = $querylogin->getwxuserinfo($params['code']);
        if (isset($data['sso']) && !empty($data['sso'])) {
            $this->_setSso($data['sso']);
            //登录成功跳回首页
            $referer = empty($_COOKIE['quickloginbackurl']) ? '/' : $_COOKIE['quickloginbackurl'];
            header('Location: ' . $referer);
            exit;
        }
        if (!isset($data['unionid'])) {
            //登录成功跳回首页
            header('Location: /member/login');
            exit;
        }
        header('Location: /');
        exit;
        $data['type'] = $params['type'];
        header('Location: /querylogin/bind/unionid/' . $data['unionid'] . '/type/' . $params['type'] . "/wxuserinfo/" . base64_encode(json_encode($data)) . '/?http_referer=' . $referer);
        exit;
    }

  
 

}
